package com.example.workflow.service.impl;

import com.example.workflow.service.LogAnalysisService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import java.time.LocalDate;


@Service
public class LogAnalysisServiceImpl implements LogAnalysisService {
    @Autowired
    private RedisTemplate<String,String> redisTemplate;

    @Override
    public void recordLogin(Integer userId) {
        String today = LocalDate.now().toString();
        String key = "login:stats:" + today;
        // 使用SET的去重特性（同一用户当天只计一次）
        redisTemplate.opsForSet().add(key, userId.toString());
    }

    /**
     * 获取当日登录人数
     *
     * @return 当日登录人数
     */
    @Override
    public int getTodayLoginCount() {
        String key = "login:stats:" + LocalDate.now().toString();
        Long size = redisTemplate.opsForSet().size(key);
        return size != null ? size.intValue() : 0;
    }

    /**
     * 统计未完成预警订单
     *
     * @return
     */
    @Override
    public int getUncompletedOrders() {

//        TODO 未完成工单
        return 0;
    }


}
